<!DOCTYPE html>
<html lang="en">
	<head>
		<title>待查</title>
		<#include "../inc/header.ftl"/>
	</head>

	<body class="no-skin">

		<div class="main-container ace-save-state" id="main-container">

			<div class="main-content">
				<div class="main-content-inner">

					<div class="page-content">
						<div class="row">
							<div id="grid-main-data" class="col-xs-12">
								<table id="MainGrid" style="min-height: 500px"></table>
								<div id="toolbar">
									<div style="padding:8px">
                                        交易流水号：<input id="bankaffirmfind" class="easyui-textbox" style="width:140px">&emsp;
                                        收款账户：<input id="accountcode" name="accountcode">
                                        收款日期：<input id="paybankdtfind" class="easyui-datebox" style="width:140px">&emsp;
                                        <a href="#" onclick="javascript:searchInfo()" class="easyui-linkbutton" iconCls="icon-search">查 询</a>
									</div>
									<div style="padding:8px 8px 4px">
                                        <a href="#" class="easyui-linkbutton" iconCls="icon-add" onclick="javascript:editInfo(1)">新增</a>
                                        <a href="#" class="easyui-linkbutton" iconCls="icon-edit" onclick="javascript:editInfo(2)">修改</a>
                                        <a href="#" class="easyui-linkbutton" iconCls="icon-cut" id="delet" onclick="javascript:deleteInfo()">删除</a>
                                        <a href="#" class="easyui-linkbutton" iconCls="icon-send" onclick="javascript:sendInfo(1)">发送</a>
                                        <a href="#" class="easyui-linkbutton" iconCls="icon-clean" onclick="javascript:cleanInfo()">清除财政待查</a>
                                        <a href="#" class="easyui-linkbutton" iconCls="icon-update" onclick="javascript:sendInfo(3)">更新财政待查</a>
                                        <a href="#" class="easyui-linkbutton" iconCls="icon-print" onclick="javascript:exportInfo()">导出</a>
									</div>
								</div>
							</div>
						</div><!-- /.row -->
					</div><!-- /.page-content -->
                    <div id="box-add" class="ui-dialog-content hide">
                        <form class="form-horizontal" id="form-add" method="post">
                            <div class="form-group">
                                <label class="control-label col-xs-12 col-sm-1 no-padding-right">收款账户名称&nbsp;</label>
                                <div class="col-xs-12 col-sm-3">
                                  <span class="block input-icon input-icon-right">
                                    <input name="bankid" id="bankid" class="col-xs-12 easyui-textbox" data-options="required:true" style="width:100%" />
                                    <input name="waitaffirmid" id="waitaffirmid" hidden>
                                  </span>
                                </div>
                                <label class="control-label col-xs-12 col-sm-1 no-padding-right">收款账户号码&nbsp;</label>
                                <div class="col-xs-12 col-sm-3">
                                    <span class="block input-icon input-icon-right">
                                        <input name="payeeaccountcode" id="payeeaccountcode" class="col-xs-12 easyui-textbox" style="width:100%" readonly />
                                    </span>
                                </div>
                                <label class="control-label col-xs-12 col-sm-1 no-padding-right">收款银行开户行	&nbsp;</label>
                                <div class="col-xs-12 col-sm-3">
                                  <span class="block input-icon input-icon-right">
                                    <input name="payeebankname" id="payeebankname" class="col-xs-12 easyui-textbox" style="width:100%" readonly />
                                  </span>
                                </div>

                            </div>
                            <div class="form-group">
                                <label class="control-label col-xs-12 col-sm-1 no-padding-right">区划&nbsp;</label>
                                <div class="col-xs-12 col-sm-3">
                                    <span class="block input-icon input-icon-right">
                                        <input name="cantonname" id="cantonname" class="col-xs-12 easyui-textbox" style="width:100%" readonly />
                                        <input hidden id="cantonid" name="cantonid">
                                    </span>
                                </div>
                                <label class="control-label col-xs-12 col-sm-1 no-padding-right">缴款人&nbsp;</label>
                                <div class="col-xs-12 col-sm-3">
                                    <span class="block input-icon input-icon-right">
                                        <input name="payer" id="payer" class="col-xs-12 easyui-textbox" data-options="required:true" style="width:100%">
                                    </span>
                                </div>
                                <label class="control-label col-xs-12 col-sm-1 no-padding-right">缴款人账号&nbsp;</label>
                                <div class="col-xs-12 col-sm-3">
                                    <span class="block input-icon input-icon-right">
                                        <input name="payeraccount" id="payeraccount" class="col-xs-12 easyui-textbox" data-options="required:true" style="width:100%">
                                    </span>
                                </div>
                            </div>
                            <div class="form-group">
                                 <label class="control-label col-xs-12 col-sm-1 no-padding-right">缴款人开户行	&nbsp;</label>
                                <div class="col-xs-12 col-sm-3">
                                    <span class="block input-icon input-icon-right">
                                         <input name="payerbank" id="payerbank" class="col-xs-12 easyui-textbox"  data-options="required:true" style="width:100%" />
                                    </span>
                                </div>

                                <label class="control-label col-xs-12 col-sm-1 no-padding-right">金额&nbsp;</label>
                                <div class="col-xs-12 col-sm-3">
                                  <span class="block input-icon input-icon-right">
                                      <input name="originfund" id="originfund" class="col-xs-12 easyui-numberbox"  data-options="precision:2,required:true" style="width:100%" />
                                  </span>
                                </div>
                                <label class="control-label col-xs-12 col-sm-1 no-padding-right">收款时间&nbsp;</label>
                                <div class="col-xs-12 col-sm-3">
                                  <span class="block input-icon input-icon-right">
                                    <input name="paybankdt" id="paybankdt" class="easyui-datetimebox col-xs-12 easyui-textbox"   style="width: 100%" data-options="required:true" />
                                  </span>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="control-label col-xs-12 col-sm-1 no-padding-right">收款网点&nbsp;</label>
                                <div class="col-xs-12 col-sm-3">
                                  <span class="block input-icon input-icon-right">
                                     <input name="bankstation" id="bankstation" class="col-xs-12 easyui-textbox" data-options="required:true" style="width:100%" />
                                  </span>
                                </div>
                                <label class="control-label col-xs-12 col-sm-1 no-padding-right">交易流水号&nbsp;</label>
                                  <div class="col-xs-12 col-sm-3">
                                    <span class="block input-icon input-icon-right">
                                      <input name="bankaffirm" id="bankaffirm" class="col-xs-12 easyui-textbox"  data-options="required:true" style="width:100%" />
                                     </span>
                                  </div>
                                <label class="control-label col-xs-12 col-sm-1 no-padding-right">核心交易流水号&nbsp;</label>
                                <div class="col-xs-12 col-sm-3">
                                  <span class="block input-icon input-icon-right">
                                      <input name="hxbankaffirm" id="hxbankaffirm" class="col-xs-12 easyui-textbox"  style="width:100%"/>
                                  </span>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="control-label col-xs-12 col-sm-1 no-padding-right">缴款方式&nbsp;</label>
                                <div class="col-xs-12 col-sm-3">
                                  <span class="block input-icon input-icon-right">
                                    <input name="payway" id="payway" class="col-xs-12 easyui-textbox" data-options="required:true" style="width: 100%"/>
                                  </span>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="control-label col-xs-12 col-sm-1 no-padding-right">附言	&nbsp;</label>
                                <div class="col-xs-12 col-sm-3">
                                      <span class="block input-icon input-icon-right">
                                          <input name="postscript" id="postscript" style="width: 600px" class="col-xs-12 easyui-textbox" data-options="required:true" />
                                        </span>
                                </div>
                            </div>
                        </form>
                    </div><!-- #dialog-confirm -->

                    <div id="SendBox-add" class="ui-dialog-content hide">
                        <div style="padding:8px">
                            复核用户编码：<input id="usercode" class="easyui-textbox" style="width:110px" data-options="required:true" >&emsp;
                            复核用户密码：<input id="userpwd" class="easyui-passwordbox" style="width:110px" data-options="required:true" >&emsp;
                            <input id="biaoshi" hidden>&emsp;
                            <a href="#" class="easyui-linkbutton" iconCls="icon-redo"  onclick="javascript:pageSendInfo()"><span  id="sendClean"></span></a>
                        </div>
                        <table id="SendMainGrid"></table>
                    </div>

                </div>
			</div><!-- /.main-content -->
		</div><!-- /.main-container -->

		<!-- basic scripts -->
		<#include "../inc/basicjs.ftl"/>

		<!-- inline scripts related to this page -->
		<script type="text/javascript">
            //列表-------------------------------------------------
			jQuery(function($) {
                // 右侧表格
                $('#MainGrid').datagrid({
                    url: prefix + '/bill/waitaffirm/findWaitaffirmPage',
                    checkbox: true,
                    pagination: true,
                    fitColumns:false,
                    striped: true,
                    singleSelect: false,
                    loadMsg: "正在加载数据，请稍后...",
                    queryParams: {accountcode:'',paybankdt:'',bankaffirm:''},
                    columns:[[
                        {field: 'ck', checkbox: true},
                        {title:'区划ID',field:'cantonid',hidden:true},
                        {title:'区划',field:'cantonname',width:80},
                        {title:'缴款人',field:'payer'},
                        {title:'缴款人账号', field:'payeraccount'},
                        {title:'缴款人开户行',field:'payerbank'},
                        {title:'收款户名',field:'payeeaccountname'},
                        {title:'收款银行账号',field:'payeeaccountcode',width:140},
                        {title:'收款银行开户行',field:'payeebankname'},
                        {title:'金额',field:'originfund',width:80},
                        {title:'收款时间', field:'paybankdt',width:130},
                        {title:'收款网点',field:'bankstation',width:100,formatter: function(value,row,index) {
                                for(var i=0;i<_bankstationdata.length;i++){
                                    if(value == _bankstationdata[i].bankstationcode) {
                                        return _bankstationdata[i].bankstationname;
                                    }
                                }
                                return value;
                            }},
                        {title:'交易流水号',field:'bankaffirm'},
                        {title:'核心交易流水号', field:'hxbankaffirm'},
                        {title:'附言',field:'postscript',width:100},
                        {title:'缴款方式', field:'payway',width:60,formatter: function(value,row,index) {
                                for(var i=0;i<_paywaydata.length;i++){
                                    if(value == _paywaydata[i].paywayid) {
                                        return _paywaydata[i].paywayname;
                                    }
                                }
                                return value;
                            }},
                        {title:'是否确认',field:'billstate',width:60,formatter: function(value,row,index){
                                if(value==3) {
                                    return '已确认';
                                }else{
                                    return '';
                                }
                            }}
                    ]],
                    toolbar: '#toolbar',
                    onBeforeLoad: function (param) {
                        // 首次打开时，不加载数据
                        var firstLoad = $(this).attr("firstLoad");  
                        if (firstLoad == "false" || typeof (firstLoad) == "undefined") {  
                            $(this).attr("firstLoad","true");  
                            return false;  
                        }  
                        return true;  
                    },
                    onDblClickRow: function (index, data) {
                        $('#form-add').form('load',data);
                        $('#bankid').combobox('disable');
                        showForm(2);
                    },
                    onLoadSuccess: function (data) {
                        if (data.total == 0) {
                            $('#grid-main-data').find('.datagrid-body').html('<div style="text-align: center;font-size: 14px;padding: 20px 0;">查询无数据</div>');
                        }
                    }
                });

                $(window).resize(function() {
                    $('#MainGrid').datagrid('resize');
                });

                //收款银行下拉框
                $('#bankid').combobox({
                    data: _bankdata,
                    valueField:'bankid',
                    textField:'accountname',
                    width:170,
                    onSelect: function (data) {
                        $('#payeeaccountcode').textbox('setText', data.accountcode);
                        $('#payeebankname').textbox('setText', data.bankname);
                        $('#cantonname').textbox('setText', data.cantonname);
                        $('#cantonid').val(data.cantonid);                    
                    }
                });

                //收款网点下拉框
                $('#bankstation').combobox({
                    data: _bankstationdata,
                    valueField:'bankstationcode',
                    textField:'bankstationname',
                    width:170,
                });
                //缴款方式下拉框
                $('#payway').combobox({
                    data: _paywaydata,
                    valueField:'paywayid',
                    textField:'paywayname',
                    panelHeight:'auto',
                });
                // 查询的下拉框
                $('#accountcode').combogrid({
                    panelWidth:550,
                    idField:'accountcode',
                    textField:'accountcode',
                    data: _bankdata,
                    columns:[[
                        {field: 'ck', checkbox: true},
                        {field:'cantonname',title:'区划',width:80},
                        {field:'accountcode',title:'账号',width:160},
                        {field:'bankname',title:'开户行名称',width:260}
                    ]]
                });
                
                // 发送复核表格
                $('#SendMainGrid').datagrid({
                    pagination: false,
                    fitColumns:false,
                    striped: true,
                    singleSelect: false,
                    loadMsg: "正在加载数据，请稍后...",
                    columns:[[
                        {title:'区划ID',field:'cantonid',hidden:true},
                        {title:'区划',field:'cantonname',width:100},
                        {title:'缴款人',field:'payer',width:100},
                        {title:'缴款人账号', field:'payeraccount',width:100},
                        {title:'缴款人开户行',field:'payerbank',width:100},
                        {title:'收款户名',field:'payeeaccountname',width:100},
                        {title:'收款银行账号',field:'payeeaccountcode',width:100},
                        {title:'收款银行开户行',field:'payeebankname',width:100},
                        {title:'金额',field:'originfund',width:100},
                        {title:'收款时间', field:'paybankdt',width:100},
                        {title:'收款网点',field:'bankstation',width:100,formatter: function(value,row,index) {
                                for(var i=0;i<_bankstationdata.length;i++){
                                    if(value == _bankstationdata[i].bankstationcode) {
                                        return _bankstationdata[i].bankstationname;
                                    }
                                }
                                return value;
                            }},
                        {title:'交易流水号',field:'bankaffirm',width:100},
                        {title:'核心交易流水号', field:'hxbankaffirm',width:100},
                        {title:'附言',field:'postscript',width:100},
                        {title:'缴款方式', field:'payway',width:100,formatter: function(value,row,index) {
                                for(var i=0;i<_paywaydata.length;i++){
                                    if(value == _paywaydata[i].paywayid) {
                                        return _paywaydata[i].paywayname;
                                    }
                                }
                                return value;
                            }},
                        {title:'是否确认',field:'billstate',width:100,formatter: function(value,row,index){
                                if(value==3) {
                                    return '已确认';
                                }else{
                                    return '';
                                }
                            }}
                    ]]
                });
            });
            // 查询按钮
			function searchInfo() {
                if ($('#accountcode').val() == '') {
                    $.messager.alert('提示', '请选择收款账户', 'info');
                    return;
                }
                $('#MainGrid').datagrid('load', {
                    accountcode: $('#accountcode').val(),
                    paybankdt: $('#paybankdtfind').val(),
                    bankaffirm: $('#bankaffirmfind').val()
                });
			}

		    //  修改页面框赋值----------------------------------------------
            function editInfo(opt) {
			    if(opt==1){
                    $('#form-add').form('clear');
                    $('#bankid').combobox('enable');
                }else{
                    var rows = $('#MainGrid').datagrid('getSelections');
                    if (rows.length == 0) {
                        $.messager.alert('提示', '请选择要编辑的数据', 'info');
                        return;
                    }
                    if (rows.length>1) {
                        $.messager.alert('提示', '修改操作不能多选', 'info');
                        return;
                    }
                    $('#form-add').form('load',rows[0]);
                    $('#bankid').combobox('disable');
                }
                showForm(opt);
            }

            function showForm(opt) {
               var tit = (opt ==2) ? '修改待查' :'新增待查';
                $( "#box-add" ).removeClass('hide').dialog({
                    title: '&nbsp;' +tit ,
                    iconCls:'icon-add',
                    width: 800,
                    height: 600,
                    modal: true,
                    buttons:[{
                        text:'保存',
                        iconCls:'icon-ok',
                        width:80,
                        plain:false,
                        handler:function(){
                            updateInfo(opt);
                        }
                    },{
                        text:'取消',
                        iconCls:'icon-cancel',
                        width:80,
                        plain:false,
                        handler:function(){$('#box-add').dialog('close')}
                    }]
                });
            }

            //待查新增修改
            function updateInfo(opt) {
                var url = (opt ==2) ? '/bill/waitaffirm/updatewaitaffirm' :'/bill/waitaffirm/savewaitaffirm';
                $('#form-add').form({
                    url: prefix + url,
                    onSubmit:function(){
                        var isValid = $(this).form('validate');
                        if (isValid){
                            $.messager.progress({
                                title: '提示',
                                msg: '数据处理中，请稍候……',
                                text: ''
                            });
                        }
                        return isValid;
                    },
                    success:function(data) {
                        $.messager.progress('close');
                        var data = eval('(' + data + ')');
                        if (data.success) {
                            searchInfo();
                            $('#box-add').dialog('close');
                        }
                        $.messager.alert('提示', data.msg, 'info');

                    }
                });
                $('#form-add').submit();
            }

            // 清除财政端待查
            function cleanInfo() {
                var accountcode = $('#accountcode').val();
                var paybankdt = $('#paybankdtfind').val();
                if(accountcode==null||accountcode==''){
                    $.messager.alert('提示', '请选择收款账户', 'info');
                    return;
                }
                if(paybankdt==null||paybankdt==''){
                    $.messager.alert('提示', '请选择收款日期', 'info');
                    return;
                }
                $('#usercode').textbox('setValue', '');
                $('#userpwd').textbox('setValue', '');
                $('#biaoshi').val(2);
                $('#sendClean').text('确认清除');
                $('#SendMainGrid').datagrid({
                    data:[]
                });
                $( "#SendBox-add" ).removeClass('hide').dialog({
                    title: '&nbsp;清除财政端待查',
                    iconCls:'icon-add',
                    width: 700,
                    height: 500,
                    modal: true,
                    buttons:[{
                        text:'取消',
                        iconCls:'icon-cancel',
                        width:80,
                        plain:false,
                        handler:function(){$('#SendBox-add').dialog('close')}
                    }]
                });
            }

            //-------发送页面弹窗
            function sendInfo(opt) {
                $('#usercode').textbox('setValue', '');
                $('#userpwd').textbox('setValue', '');
                $('#biaoshi').val(opt);
                var row = $('#MainGrid').datagrid('getSelections');
                if (row.length == 0) {
                    $.messager.alert('提示', '请选择要发送的数据', 'info');
                    return;
                }
                var tit = '发送待查';
                $('#sendClean').text('确认发送');

                $( "#SendBox-add" ).removeClass('hide').dialog({
                    title: '&nbsp;'+tit,
                    iconCls:'icon-send',
                    width: 600,
                    height: 500,
                    modal: true,
                    buttons:[{
                        text:'取消',
                        iconCls:'icon-cancel',
                        width:80,
                        plain:false,
                        handler:function(){$('#SendBox-add').dialog('close')}
                    }]
                });

                // 右侧表格
                $('#SendMainGrid').datagrid({
                    data:row,
                });
            }
            //  ----------------确认发送
            function pageSendInfo() {
                var usercode = $('#usercode').val();
                var userpwd = $('#userpwd').val();
                if(usercode==null||usercode==''){
                    $.messager.alert('提示', '请输入用户编码', 'info');
                    return;
                }
                if(userpwd==null||userpwd==''){
                    $.messager.alert('提示', '请输入用户密码', 'info');
                    return;
                }

                var opt = $('#biaoshi').val();
                var url = '';

                var da={};
                if(opt==2){
                    var accountcode = $('#accountcode').val();
                    var paybankdt = $('#paybankdtfind').val();
                    url = '/bill/waitaffirm/cleanwaitaffirm';
                    da = {
                        usercode: usercode,
                        userpwd:userpwd,
                        accountcode:accountcode,
                        paybankdt:paybankdt
                    };
                }else{
                    var row = $('#SendMainGrid').datagrid('getData');
                    var list = [];
                    $.each(row.rows,function(index, value) {
                        list.push(value.waitaffirmid);
                    });
                    var types = null;
                    if(opt==1){
                        url = '/bill/waitaffirm/sendwaitaffirm';
                    }else{
                        url = '/bill/waitaffirm/resetwaitaffirm';
                    }
                    da = {
                        usercode: usercode,
                        userpwd:userpwd,
                        billids:list.toString()
                    };
                }
                $.messager.progress({
                   title: '提示',
                   msg: '数据处理中，请稍候……',
                   text: ''
                });
                $.ajax({
                    url: prefix +url,
                    type: 'POST',
                    data: da,
                    dataType: 'json',
                    success:function(data){
                        $.messager.alert('提示', data.msg, 'info', function() {
                            if (data.success) $('#SendBox-add').dialog('close');
                            $.messager.progress('close');
                        });
                    },
                    error : function(XMLHttpRequest, textStatus, errorThrown) {
                        $.messager.alert('提示', '提交失败', 'info');
                        $.messager.progress('close');
                    }
                });
            }
            // 导出
            function exportInfo() {
                var accountcode = $('#accountcode').val();
                if (accountcode == '') {
                    $.messager.alert('提示', '请选择收款账户', 'info');
                    return;
                }
                var paybankdt = $('#paybankdtfind').val();
                if (paybankdt == '') {
                    $.messager.alert('提示', '请选择收款日期', 'info');
                    return;
                }
                var downurl = prefix + '/bill/waitaffirm/waitaffirmExport?accountcode=' + accountcode + '&paybankdt=' + paybankdt;
                window.location.href = downurl;
            }
            
            // ------删除
            function deleteInfo() {
                row = $('#MainGrid').datagrid('getSelections');
                if (row.length == 0) {
                    $.messager.alert('提示', '请选择要发送的数据', 'info');
                    return;
                }

                var list = [];
                $.each(row,function(index, value) {
                    list.push(value.waitaffirmid);
                });

                $.messager.confirm('确认','您确认想要删除记录吗？',function(r){
                    if (r){
                        $.ajax({
                            url: prefix +'/bill/waitaffirm/delwaitaffirm',
                            type: 'POST',
                            data: {
                                waitaffirmids: list.toString()
                            },
                            dataType: 'json',
                            success:function(data){
                                searchInfo();
                                $.messager.alert('提示', data.msg, 'info');
                            }
                        });
                    } else{//没选中
                        return false;
                    }
                })
            }


        </script>
	</body>
</html>
